package com.byzx.wine.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.byzx.wine.dao.SyauthorityDao;
import com.byzx.wine.dao.SyroleauthorityMapper;
import com.byzx.wine.dao.SyuserDao;
import com.byzx.wine.po.Syauthority;
import com.byzx.wine.po.Syroleauthority;
import com.byzx.wine.service.SyuserServices;

@Service
public class SyuserServiceImpl implements SyuserServices{
	@Autowired
	private SyauthorityDao syauthorityDao;
	@Autowired
	private SyuserDao sy;
	@Autowired
	private SyroleauthorityMapper syroleauthorityMapper;
//	@Autowired
//	private Syrole syrole;

	
	
	
	@Override
	public List<Map<String, Object>> selectAll(Integer id) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		List<Syroleauthority> list1 = sy.selectById(id);
		List<Syauthority> l=sy.selectAll();
		for (int i = 0; i< l.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", l.get(i).getId());
			map.put("pid", l.get(i).getPid());
			map.put("name", l.get(i).getName());
			map.put("src", l.get(i).getSrc());
			map.put("open", false);
			for (int j = 0; j < list1.size(); j++) {
				if (list1.get(j).getAuthid().equals(l.get(i).getId())) {
					map.put("checked", true);
				} else {
					map.put("checked", false);
				}
			}
			
			list.add(map);
		}
		return list;
	}

	//授权传后台
	public Integer shouquan (Integer id,String ids) {
		Integer back = 0;
		String[] idd = ids.split(",");
		for (int i = 0; i < idd.length; i++) {
			Syroleauthority s = new Syroleauthority();
			s.setAuthid(Integer.parseInt(idd[i]));
			s.setRoleid(id);
			back += syroleauthorityMapper.insertSelective(s);
		}
		return back;
		
	}

}
